if(length(tryCatch(list.dirs(path="~/Library/CloudStorage/Dropbox/Robots and Trade in Services"),error=function(e) e))==0){
  base.path<-"~/Dropbox/Robots and Trade in Services/"
} else {
  base.path<-"~/Library/CloudStorage/Dropbox/Robots and Trade in Services/"
}

#Load data and functions
source(paste0(base.path,"Drafts/Replication/06 Functions and Processing -- Exp 2.R"))

#############
## Table 4 ##
#############

controls_vec<-c("educ_nodegree","educ_ba","male","hispanicbin","region","white","black","hispanicbin","hhi.num","party_dem","party_rep")

# Foreign treatment raises the regulations-benefits difference
m1 <- df.raw %>% lm(diff.btw23~tmt.foreign, .)
#   With controls
m2 <- df.raw %>% lm(paste0("diff.btw23~tmt.foreign +",paste(controls_vec,collapse=" + ")), .)

# Foreign treatment flavors raise the regulations-benefits difference
m3 <- df.raw %>% lm(diff.btw23~treatment, .)
#   With controls
m4 <- df.raw %>% lm(paste0("diff.btw23~treatment +",paste(controls_vec,collapse=" + ")), .)

# Interaction term model with above/below 60 (the median)
df.raw <- df.raw %>% mutate(imgood_pre_above60 = case_when(
  importsgoodpret_1 >= 60 ~ 1,
  importsgoodpret_1 < 60 ~ 0
))

# Interaction term version 1
m5 <- df.raw %>% lm(diff.btw23~tmt.foreign*imgood_pre_above60, .)
#   With controls
m6 <- df.raw %>% lm(paste0("diff.btw23~tmt.foreign*imgood_pre_above60 +",paste(controls_vec,collapse=" + ")), .)

stargazer(m1, m2, m3, m4, m5, m6, se = estimatr::starprep(m1,m2,m3,m4,m5,m6),
          keep.stat="n", header = FALSE,
          title="Effect of Treatments on Difference (Regul. - Transfers), Between-respondent estimates",
          label = "tab:fubetweenfull",
          omit.table.layout ="dl",
          keep = c("tmt.foreign","treatment2","treatment3","treatment4","imgood_pre_above60","Constant"),
          covariate.labels=c("Foreign","For. - Reliance","For. - Rel. Gains","For. - Within","Imports Good > 60","Foreign*Imp. Good > 60"),
          add.lines=list(c("Controls?", "N", "Y","N","Y","N","Y")), no.space=TRUE)


